package course.arraysearch;

public class HalfSearch {
    public static void main(String[] args) {
        int [] arr = {1,2,3,4,5,6,7,8,9};
        int number = 3;
        System.out.println(halfSearch(arr,number));
    }

    private static int halfSearch(int [] arr, int number){
        int max = arr.length-1;
        int min = 0;
        while (min <= max) {
            int mid = (max+min) >> 1;
            if(number > arr[mid]){
                min = mid +1;
            } else if (number < arr[mid]) {
                max = mid-1;
            }else{
                return mid;
            }
        }
        return -1;
    }
}
